package org.springblade.modules.restaurant.job;

import cn.hutool.core.date.DateUtil;
import com.aizuda.snailjob.client.job.core.annotation.JobExecutor;
import com.aizuda.snailjob.client.job.core.dto.JobArgs;
import com.aizuda.snailjob.client.model.ExecuteResult;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.modules.restaurant.service.IOperatingIncomeService;
import org.springframework.stereotype.Component;

/**
 * 营业额 计算
 *
 * @author harry
 * @公众号 Harry技术
 */
@Slf4j
@Component
@AllArgsConstructor
@JobExecutor(name = "operatingIncomeJobExecutor")
public class OperatingIncomeJobExecutor {
	private final IOperatingIncomeService operatingIncomeService;

	public ExecuteResult jobExecute(JobArgs jobArgs) {
		log.info("计算营业额===>jobArgs:{}", jobArgs);

		String time = DateUtil.formatDate(DateUtil.date());
		operatingIncomeService.calculateOperatingIncome(time);

		String yesterday = DateUtil.formatDate(DateUtil.yesterday());
		operatingIncomeService.calculateOperatingIncome(yesterday);

		return ExecuteResult.success();
	}

//	@PostConstruct
	public void init() {
		for (int i = 0; i < 20; i++) {
			String time = DateUtil.formatDate(DateUtil.offsetDay(DateUtil.date(), -(19 - i)));
			operatingIncomeService.calculateOperatingIncome(time);
		}
	}
}
